<template>
<view class="content">
	<view :style='{"minHeight":"100vh","width":"100%","padding":"24rpx","position":"relative","background":"url(http://codegen.caihongy.cn/20240112/23f959aa396c4607b2f20ed40caa81e9.jpg) no-repeat center top / 100% auto,#f5f5f5","height":"auto"}'>
		<form :style='{"width":"100%","padding":"24rpx","borderRadius":"16rpx","background":"#fff","display":"block","height":"auto"}' class="app-update-pv">
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">路线编号</view>
				<view :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","flex":"1","background":"rgba(255,255,255,.6)","lineHeight":"80rpx","fontSize":"32rpx"}' class="right-input">
					{{ruleForm.luxianbianhao}}
				</view>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">路线名称</view>
				<input :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255,255,255,.6)","fontSize":"32rpx","height":"80rpx"}' :disabled="ro.luxianmingcheng" v-model="ruleForm.luxianmingcheng" placeholder="路线名称"  type="text"></input>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class=" select">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">景点名称</view>
				<picker :disabled="ro.jingdianmingcheng" :style='{"border":"2rpx solid #fff","width":"100%","padding":"0","flex":"1","background":"rgba(255,255,255,.6)","height":"auto"}' @change="jingdianmingchengChange" :value="jingdianmingchengIndex" :range="jingdianmingchengOptions">
					<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"32rpx","color":"#666"}' class="uni-input">{{jingdianmingchengOptions[jingdianmingchengIndex]}}</view>
				</picker>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">景点类型</view>
				<input :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255,255,255,.6)","fontSize":"32rpx","height":"80rpx"}' disabled v-model="ruleForm.jingdianleixing" placeholder="景点类型"></input>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">详细地址</view>
				<input :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255,255,255,.6)","fontSize":"32rpx","height":"80rpx"}' disabled v-model="ruleForm.xiangxidizhi" placeholder="详细地址"></input>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="" @tap="luxiantupianTap">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">路线图片</view>
				<image :style='{"width":"80rpx","margin":"0","borderRadius":"100%","objectFit":"cover","display":"block","height":"80rpx"}' class="avator" v-if="ruleForm.luxiantupian" :src="baseUrl+ruleForm.luxiantupian.split(',')[0]" mode="aspectFill"></image>
				<image :style='{"width":"80rpx","margin":"0","borderRadius":"100%","objectFit":"cover","display":"block","height":"80rpx"}' class="avator" v-else src="../../static/gen/upload.png" mode="aspectFill"></image>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">起点</view>
				<input :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255,255,255,.6)","fontSize":"32rpx","height":"80rpx"}' :disabled="ro.qidian" v-model="ruleForm.qidian" placeholder="起点"  type="text"></input>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">途径路段</view>
				<input :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255,255,255,.6)","fontSize":"32rpx","height":"80rpx"}' :disabled="ro.tujingluduan" v-model="ruleForm.tujingluduan" placeholder="途径路段"  type="text"></input>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">终点</view>
				<input :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255,255,255,.6)","fontSize":"32rpx","height":"80rpx"}' :disabled="ro.zhongdian" v-model="ruleForm.zhongdian" placeholder="终点"  type="text"></input>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">出行方式</view>
				<input :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255,255,255,.6)","fontSize":"32rpx","height":"80rpx"}' :disabled="ro.chuxingfangshi" v-model="ruleForm.chuxingfangshi" placeholder="出行方式"  type="text"></input>
			</view>
 

			<view :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"#ccc","borderWidth":"0 0 0px 0","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"margin":"0 0 0 24rpx","color":"#999","width":"auto","lineHeight":"80rpx","fontSize":"32rpx","minWidth":"160rpx","fontWeight":"500"}' class="title">路线详情</view>
                <xia-editor ref="editor" :style='{"border":"2rpx solid #ddd","minHeight":"360rpx","padding":"20rpx","color":"#666","borderRadius":"8rpx","background":"rgba(255,255,255,.6)","width":"100%","height":"auto"}' v-model="ruleForm.luxianxiangqing" placeholder="路线详情" @editorChange="luxianxiangqingChange"></xia-editor>
			</view>
			
			<view :style='{"width":"100%","flexWrap":"wrap","justifyContent":"space-between","display":"flex","height":"auto"}' class="btn" >
				<button :style='{"border":"0","padding":"0px","margin":"0 0 40rpx","color":"#fff","borderRadius":"32rpx","background":"#4AB030","width":"100%","lineHeight":"80rpx","fontSize":"32rpx","height":"80rpx"}' @tap="onSubmitTap" class="bg-red">提交</button>
			</view>
		</form>

	</view>
</view>
</template>

<script>
	import wPicker from "@/components/w-picker/w-picker.vue";
    import xiaEditor from '@/components/xia-editor/xia-editor';
    import multipleSelect from "@/components/momo-multipleSelect/momo-multipleSelect";
	export default {
		data() {
			return {
				cross:'',
				ruleForm: {
				luxianbianhao: this.getUUID(),
				luxianmingcheng: '',
				jingdianmingcheng: '',
				jingdianleixing: '',
				xiangxidizhi: '',
				luxiantupian: '',
				qidian: '',
				tujingluduan: '',
				zhongdian: '',
				chuxingfangshi: '',
				luxianxiangqing: '',
				storeupnum: '',
				},
				jingdianmingchengOptions: [],
				jingdianmingchengIndex: 0,
				// 登录用户信息
				user: {},
                ro:{
                   luxianbianhao : false,
                   luxianmingcheng : false,
                   jingdianmingcheng : false,
                   jingdianleixing : false,
                   xiangxidizhi : false,
                   luxiantupian : false,
                   qidian : false,
                   tujingluduan : false,
                   zhongdian : false,
                   chuxingfangshi : false,
                   luxianxiangqing : false,
                   storeupnum : false,
                },
			}
		},
		components: {
			wPicker,
            xiaEditor,
            multipleSelect,
		},
		computed: {
			baseUrl() {
				return this.$base.url;
			},



		},
		async onLoad(options) {
			let table = uni.getStorageSync("nowTable");
			// 获取用户信息
			let res = await this.$api.session(table);
			this.user = res.data;
			
			// ss读取


			// 下2
			res = await this.$api.option(`lvyoujingdian`,`jingdianmingcheng`,{});
			this.jingdianmingchengOptions = res.data;

			// 如果有登录，获取登录后保存的userid
			this.ruleForm.userid = uni.getStorageSync("appUserid")
			if (options.refid) {
				// 如果上一级页面传递了refid，获取改refid数据信息
				this.ruleForm.refid = Number(options.refid);
				this.ruleForm.nickname = uni.getStorageSync("nickname");
			}
			// 如果是更新操作
			if (options.id) {
				this.ruleForm.id = options.id;
				// 获取信息
				res = await this.$api.info(`jingdianluxian`, this.ruleForm.id);
				this.ruleForm = res.data;
			}
			// 跨表
			this.cross = options.cross;
			if(options.cross){
				var obj = uni.getStorageSync('crossObj');
				for (var o in obj){
					if(o=='luxianbianhao'){
					this.ruleForm.luxianbianhao = obj[o];
					this.ro.luxianbianhao = true;
					continue;
					}
					if(o=='luxianmingcheng'){
					this.ruleForm.luxianmingcheng = obj[o];
					this.ro.luxianmingcheng = true;
					continue;
					}
					if(o=='jingdianmingcheng'){
					this.ruleForm.jingdianmingcheng = obj[o];
					this.ro.jingdianmingcheng = true;
					continue;
					}
					if(o=='jingdianleixing'){
					this.ruleForm.jingdianleixing = obj[o];
					this.ro.jingdianleixing = true;
					continue;
					}
					if(o=='xiangxidizhi'){
					this.ruleForm.xiangxidizhi = obj[o];
					this.ro.xiangxidizhi = true;
					continue;
					}
					if(o=='luxiantupian'){
					this.ruleForm.luxiantupian = obj[o].split(",")[0];
					this.ro.luxiantupian = true;
					continue;
					}
					if(o=='qidian'){
					this.ruleForm.qidian = obj[o];
					this.ro.qidian = true;
					continue;
					}
					if(o=='tujingluduan'){
					this.ruleForm.tujingluduan = obj[o];
					this.ro.tujingluduan = true;
					continue;
					}
					if(o=='zhongdian'){
					this.ruleForm.zhongdian = obj[o];
					this.ro.zhongdian = true;
					continue;
					}
					if(o=='chuxingfangshi'){
					this.ruleForm.chuxingfangshi = obj[o];
					this.ro.chuxingfangshi = true;
					continue;
					}
					if(o=='luxianxiangqing'){
					this.ruleForm.luxianxiangqing = obj[o];
					this.ro.luxianxiangqing = true;
					continue;
					}
					if(o=='storeupnum'){
					this.ruleForm.storeupnum = obj[o];
					this.ro.storeupnum = true;
					continue;
					}
				}
			}
			this.styleChange()
            this.$forceUpdate()
			
			if (uni.getStorageSync('raffleType') && uni.getStorageSync('raffleType') != null) {
				uni.removeStorageSync('raffleType')
				setTimeout(() => {
					this.onSubmitTap()
				}, 300)
			}
		},
		methods: {
            luxianxiangqingChange(e) {
                this.ruleForm.luxianxiangqing = e
            },
			styleChange() {
				this.$nextTick(()=>{
					// document.querySelectorAll('.app-update-pv . .uni-input-input').forEach(el=>{
					//   el.style.backgroundColor = this.addUpdateForm.input.content.backgroundColor
					// })
				})
			},
			// 下二随
			async jingdianmingchengChange (e) {
				this.jingdianmingchengIndex = e.target.value
				this.ruleForm.jingdianmingcheng = this.jingdianmingchengOptions[this.jingdianmingchengIndex]
				let res = await this.$api.follow(`lvyoujingdian`, `jingdianmingcheng`,{
					columnValue: this.ruleForm.jingdianmingcheng
				});
				if(res.data.jingdianleixing){
					this.ruleForm.jingdianleixing = res.data.jingdianleixing
				}
				if(res.data.xiangxidizhi){
					this.ruleForm.xiangxidizhi = res.data.xiangxidizhi
				}
			},

			// 多级联动参数




			luxiantupianTap() {
				let _this = this;
				this.$api.upload(function(res) {
					_this.ruleForm.luxiantupian = 'upload/' + res.file;
					_this.$forceUpdate();
					_this.$nextTick(()=>{
						_this.styleChange()
					})
				});
			},

			getUUID () {
				return new Date().getTime();
			},
			async onSubmitTap() {
				if(this.ruleForm.luxianbianhao){
					this.ruleForm.luxianbianhao = String(this.ruleForm.luxianbianhao)
				}
//跨表计算判断
				var obj;
				if((!this.ruleForm.luxianmingcheng)){
					this.$utils.msg(`路线名称不能为空`);
					return
				}
				if((!this.ruleForm.jingdianmingcheng)){
					this.$utils.msg(`景点名称不能为空`);
					return
				}
				if(this.ruleForm.storeupnum&&(!this.$validate.isIntNumer(this.ruleForm.storeupnum))){
					this.$utils.msg(`收藏数应输入整数`);
					return
				}
				//更新跨表属性
				var crossuserid;
				var crossrefid;
				var crossoptnum;
				if(this.cross){
                    uni.setStorageSync('crossCleanType',true);
					var statusColumnName = uni.getStorageSync('statusColumnName');
					var statusColumnValue = uni.getStorageSync('statusColumnValue');
					if(statusColumnName!='') {
                        if(!obj) {
						    obj = uni.getStorageSync('crossObj');
                        }
						if(!statusColumnName.startsWith("[")) {
							for (var o in obj){
								if(o==statusColumnName){
									obj[o] = statusColumnValue;
								}

							}
							var table = uni.getStorageSync('crossTable');
							await this.$api.update(`${table}`, obj);
						} else {
						       crossuserid=Number(uni.getStorageSync('appUserid'));
						       crossrefid=obj['id'];
						       crossoptnum=uni.getStorageSync('statusColumnName');
						       crossoptnum=crossoptnum.replace(/\[/,"").replace(/\]/,"");
						}
					}
				}
				if(crossrefid && crossuserid) {
					this.ruleForm.crossuserid=crossuserid;
					this.ruleForm.crossrefid=crossrefid;
					let params = {
						page: 1,
						limit:10,
						crossuserid:crossuserid,
						crossrefid:crossrefid,
					}
					let res = await this.$api.list(`jingdianluxian`, params);
					if (res.data.total >= crossoptnum) {
						this.$utils.msg(uni.getStorageSync('tips'));
                        uni.removeStorageSync('crossCleanType');
						return false;
					} else {
                //跨表计算
						if(this.ruleForm.id){
							await this.$api.update(`jingdianluxian`, this.ruleForm);
						}else{
							await this.$api.add(`jingdianluxian`, this.ruleForm);
						}
						this.$utils.msgBack('提交成功');
					}
				} else {
                //跨表计算
					if(this.ruleForm.id){
						await this.$api.update(`jingdianluxian`, this.ruleForm);
					}else{
						await this.$api.add(`jingdianluxian`, this.ruleForm);
					}
					this.$utils.msgBack('提交成功');
				}
			},
			optionsChange(e) {
				this.index = e.target.value
			},
			bindDateChange(e) {
				this.date = e.target.value
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			toggleTab(str) {
				if(this.ro[str]){
					return false
				}
				this.$refs[str].show();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: calc(100vh - 44px);
		box-sizing: border-box;
	}
</style>
